<div class="admin_left actions">
	<h3><?php echo __('Actions'); ?></h3>
	<ul>

		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Purchases'), array('action' => 'index')); ?></li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Items'), array('controller' => 'items', 'action' => 'index')); ?> </li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('New Item'), array('controller' => 'items', 'action' => 'add')); ?> </li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('List Suppliers'), array('controller' => 'suppliers', 'action' => 'index')); ?> </li>
		<li style="list-style-type:none; margin-bottom:20%;"><?php echo $this->Html->link(__('New Supplier'), array('controller' => 'suppliers', 'action' => 'add')); ?> </li>
	</ul>
</div>


<div class="admin_right purchases form">

	<div id=breadcrumbAdmin>
		<?php $this->Html->addCrumb('Purchases', '/Purchases/index'); ?>
    	<?php $this->Html->addCrumb('Add', '/Purchases/add', array('style'=> ('color:#EB1E70;'))); ?>
    	<?php echo $this->Html->getCrumbs(' > ', array( 'text' => 'Transactions', 'url' => array('controller' => 'Sales', 'action' => 'index', 'plugin' => null), 'escape' => false)); ?>
	</div>

<?php echo $this->Form->create('Purchase'); ?>
	<fieldset>
		<legend><?php echo __('Add Purchase'); ?></legend>
	<?php
		echo $this->Form->input('Purchase.item_id');
	    echo $this->Form->button('New Item', array('type'=> 'button', 'class' => 'item-popup-window'));
		echo $this->Form->input('Purchase.supplier_id');
		echo $this->Form->button('New Supplier', array('type'=> 'button', 'class' => 'supplier-popup-window'));
		echo $this->Form->input('Purchase.price');
		echo $this->Form->input('Purchase.note');
	?>
	</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>


<!- function -->

<script type="text/javascript">

    $(document).ready(function() {
	
        $('.supplier-popup-window').click(function(){

           var popupBoxSupplier = '#popup-box-supplier';

           $(popupBoxSupplier).fadeIn(400);

           var popMargTop = ($(popupBoxSupplier).height() + 24) /2;
           var popMargLeft = ($(popupBoxSupplier).height() + 24) /2;

           $(popupBoxSupplier).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });


        $('.item-popup-window').click(function(){

           var popupBoxItem = '#popup-box-item';

           $(popupBoxItem).fadeIn(400);

           var popMargTop = ($(popupBoxItem).height() + 24) /2;
           var popMargLeft = ($(popupBoxItem).height() + 24) /2;

           $(popupBoxItem).css({
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
           });

           $('body').append('<div id="mask"></div>');
           $('#mask').fadeIn(400);
           return false;

        });


        $('button.close, #mask').bind('click', function(){
            $('#mask, #popup-box-item, #popup-box-supplier').fadeOut(400, function(){
                $('#mask').remove();
            });
            return false;

        });



    });


$(document).keyup(function(e) {
    if ( e.keyCode == 27) {
        $('#mask, #popup-box-item, #popup-box-supplier').fadeOut(400);
        return false;
    }
});

</script>
<!-- end  function -->





<!-- popup button for Consigner begins -->
<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-supplier" class="popupInfo">

	<?php echo $this->Form->create('Supplier',array("url"=>array("controller"=>"Suppliers"))); ?>
	<h4>New Supplier</h4>
	<input type="hidden" value="<?php echo rand(1000, 9999)?>" name="random" style="height:25px;" />
	<?php
		echo $this->Form->input('company_name');
		echo $this->Form->input('address');
		echo $this->Form->input('email');
		echo $this->Form->input('phone');
		echo $this->Form->input('status_id',array("url"=>array('controller'=>'suppliers')));
	?>


	<button type="button" class="close">Close</button><br>
	<?php echo $this->Form->end(__('Submit')); ?>

</div>

<script type="text/javascript">
$(document).ready(function(){
	 $('#SupplierAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 //Save successful, reload page
			 if(data.status){
				 $("#PurchaseSupplierId").empty();
				 $.each(data.supplierlist,function(index,elem){
					 $("#PurchaseSupplierId").append("<option value="+elem.id+">"+elem.company_name+"</option>");
					 });
				}
			$('#mask, .popupInfo').fadeOut(400);
			$("#SupplierAddForm #SupplierName").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for Consigner ends -->

<!-- popup button for item begins -->

<?php echo $this->Html->script('jquery.form'); ?>
<div id="popup-box-item" class="popupInfoItem">

     <div id="infoleft">	
	<?php echo $this->Form->create('Item',array("url"=>array("controller"=>"Items"),'type'=>'file')); ?>
        <?php //echo $this->Form->create('Item',array('type'=>'file')); ?>
        <h4>New Item</h4>
        <input type="hidden" value="<?php echo rand(1000, 9999)?>" name="random" style="height:25px;" />
        <?php echo $this->Form->input('name',array("type"=>"text")); ?>
		
    	<?php		
		$is_consignments = array('Consignment' => 'Consignment', 'normal' => 'normal');
		echo $this->Form->input('Item.is_consignment', array('options' => $is_consignments, 'default' => 'normal'));
		?>
		
        <?php echo $this->Form->input('brands',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('colors',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('conditions',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('sizes',array("url"=>array('controller'=>'items'))); ?>
        <?php echo $this->Form->input('categories',array("url"=>array('controller'=>'items'))); ?>


        <!--<?php echo $this->Form->input('itemStatuses',array("url"=>array('controller'=>'items'))); ?>-->

        <?php echo $this->Form->input('description'); ?>

     </div>

    <div id="inforight">

     <?php $onlines = array('Yes' => 'Yes', 'No' => 'No'); ?>
        <?php echo $this->Form->input('Item.online', array('options' => $onlines, 'default' => 'No')); ?>

       <?php $locations = array_combine( array('Backstorage', 'Shelf'),array('Backstorage', 'On Display')); ?>
        <?php echo $this->Form->input('Item.location', array('options' => $locations, 'default' => 'Backstorage')); ?>
        <?php echo $this->Form->input('Item.original_price'); ?>
        <?php $is_discounted = array('Yes' => 'Yes', 'No' => 'No'); ?>
        <?php echo $this->Form->input('Item.is_discounted', array('options' => $is_discounted, 'default' => 'No'));?>
       <!-- <?php echo $this->Form->input('image_id'); ?> -->

        <div class="addPhotosFields" id="addPhotosFields">
        <?php
         echo $this->Form->input('Image.0.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
         echo $this->Form->input('Image.1.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
         echo $this->Form->input('Image.2.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
	 echo $this->Form->input('Image.3.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
	 echo $this->Form->input('Image.4.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
	 echo $this->Form->input('Image.5.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
	 echo $this->Form->input('Image.6.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
	 echo $this->Form->input('Image.7.name', array('label' => false, 'div' => false, 'type' => 'file', 'class' => 'addPhotoButton'));
          ?>
        <button type="button" class="close">Close</button><br>
        <br/><?php echo $this->Form->end(__('Submit')); ?>
        </div>
    </div>





<script type="text/javascript">
$(document).ready(function(){
	 $('#ItemAddForm').ajaxForm({
		 complete: function (xhr) {
			 var data = JSON.parse(xhr.responseText);
			 alert(data.message);
			 //Save successful, reload page
			 if(data.status){
				 $("#PurchaseItemId").empty();
				 $.each(data.itemlist,function(index,elem){
					 $("#PurchaseItemId").append("<option value="+elem.id+">"+elem.name+"</option>");
					 });
				}
			$('#mask, .popupInfoItem').fadeOut(400);
			$("#ItemAddForm #ItemName").val("");
		    return false;
		   }
		});

});
</script>
<!-- popup button for item ends -->







